<!--
    参数：
    parms           流程信息

    方法:
    backPage        返回
 -->
<template>
    <card>
        <Alert>
            <Row style="text-align: right;">
                <Button icon="md-checkmark" type="success" @click="processSubmission" :loading="submitLoading">提交</Button>
                <Button @click="backPage" icon="md-backspace" type="primary">返回</Button>
            </Row>
        </Alert>
        <Tabs type="card" :animated="false">
            <TabPane label="审批信息" name="proposal">
                <auditProductUpdateInfo :planId="parms.planId" :stageId="parms.stageId" :isBack="isBack" ref="child"/>
            </TabPane>
            <TabPane label="修改信息" name="name2">
                <productUpdateInformation :parentParam="parentParam" :planId="productPlanId" :op="op" />
            </TabPane>
            <TabPane label="附件信息" name="name3">
                <productLaunchTabTwo :planId="productPlanId" :op="op" />
            </TabPane>
        </Tabs>
    </card>
</template>
<script>
    //修改页面组件导入
    import auditProductUpdateInfo from "./auditProductUpdateInfo.vue";
    import productUpdateInformation from "./productUpdateInfomation.vue";
    import productLaunchTabTwo from "../common/common-attachment.vue";

    //产品修改方案查询
    import {
        processSubmission,
        getApprovePlanDetail,
        submitApproveProcess,
    } from "@/projects/afs-core-business/api/afs-product/product-plan-approve/approve";

    export default {
        name: "product-launch-info",
        props: {
            parms: {
                Object
            },
        },
        components: {
            productUpdateInformation,
            productLaunchTabTwo,
            auditProductUpdateInfo,
        },
        data() {
            return {
                submitLoading: false,
                //方案ID
                productPlanId:null,

                op:'view',
                parentParam:{
                    status: 'view',
                    id: null,
                    templateCategory: null,
                    productTemplateId: null,
                },
                isBack:true,
            }
        },
        methods: {
            //返回
            backPage() {
                this.$emit("backPage", "返回");
            },
            //提交
            processSubmission() {
                let result = this.$refs['child'].validateForm();
                if (result.flag) {
                    this.submitLoading = true;
                    let productImplemente = result.productImplemente;
                    productImplemente["isUpdate"] = false;
                    productImplemente["isFinalJudgment"] = false;
                    productImplemente["id"] = this.parms.planId;
                    if ('start' == this.parms.taskNodeId ) {
                        productImplemente["isUpdate"] = true;
                    }
                    if ('end' == this.parms.taskNodeId ) { //终审
                        productImplemente["isFinalJudgment"] = true;
                    }
                    submitApproveProcess(productImplemente).then(res => {
                        this.submitLoading = false;
                        if (res.code === "0000") {
                            this.backPage();
                            this.$Message.success("流程提交成功！");
                        }
                    }).catch(() => {
                        this.submitLoading = false;
                    });
                }
            },
        },
        mounted() {
            getApprovePlanDetail({id:this.parms.planId}).then(res => {
                if (res.code === "0000") {
                    this.parentParam.productTemplateId = res.data.productTemplateId;
                    this.parentParam.templateCategory = res.data.templateCategory;
                    this.parentParam.id = res.data.id;
                }
            });
            if ('start' == this.parms.taskNodeId ) {
                this.isBack = false;
            }
        },
        created() {
            this.productPlanId =  this.parms.planId;
        },
    };
</script>
